package com.masterclient.app.base;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.masterclient.app.R;


public class CashCommonDialog extends Dialog{
    String title;
    String cancel;
    String confirm;
    int type;
    public CashCommonDialog(@NonNull Context context, String title, String cancel, String confirm) {
        super(context,R.style.MyDialog);
        this.title = title;
        this.cancel = cancel;
        this.confirm = confirm;
    }

    public CashCommonDialog(@NonNull Context context, String title, String cancel, String confirm, int type) {
        super(context,R.style.MyDialog);
        this.title = title;
        this.cancel = cancel;
        this.confirm = confirm;
        this.type = type;
    }

    private TextView tv_title,tv_cancel,tv_confirm;
    View line;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_cash_common);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_cancel = (TextView) findViewById(R.id.tv_cancel);
        tv_confirm = (TextView) findViewById(R.id.tv_confirm);
        line = findViewById(R.id.line);
        switch (type){
            case 1:
                tv_cancel.setVisibility(View.GONE);
                line.setVisibility(View.GONE);
                tv_confirm.setBackgroundResource(R.drawable.cash_common_dialog_confirm1_bkg);
                break;
        }

        tv_title.setText(title);
        tv_cancel.setText(cancel);
        tv_confirm.setText(confirm);

        tv_cancel.setOnClickListener(v->{
            if(onChooseListerner!=null){
                onChooseListerner.cancel();
            }
        });
        tv_confirm.setOnClickListener(v->{
            if(onChooseListerner!=null){
                onChooseListerner.confirm();
            }
        });

    }

    public void setOneButton(){
        tv_cancel.setVisibility(View.GONE);
        line.setVisibility(View.GONE);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowparams = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }

    public void setOnChooseListerner(OnChooseListerner onChooseListerner) {
        this.onChooseListerner = onChooseListerner;
    }

    private OnChooseListerner onChooseListerner;

    public interface OnChooseListerner{
        public void cancel();
        public void confirm();
    }
}
